<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>逾期催收列表 任务分配</title>
    <style type="text/css">
        .searchArea .fieldBox .label{width: 70px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">客户名称</div>
                    <div class="field">
                        <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">任务人</div>
                    <div class="field">
                        <input name="usrNm" id="usrNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">客户经理</div>
                    <div class="field">
                        <input name="cstMgrNm" id="cstMgrNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">合同编号</div>
                    <div class="field">
                        <input name="lsCntNo" id="lsCntNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">事业部</div>
                    <div class="field">
                        <input name="buOrgCd" id="buOrgCd" placeholder="请选择" ltype="combobox">
                    </div>
                </div>

                <div class="fieldBox">
                    <div class="label">逾期天数</div>
                    <div class="field">
                        <input ligerui="width: 82" name="ovdDaysMin" id="ovdDaysMin" type="text" class="ui-textbox"
                               value="" validate="{number:true}">
                        -
                        <input ligerui="width: 82" name="ovdDaysMax" id="ovdDaysMax" type="text" class="ui-textbox"
                               value="" validate="{number:true}">
                    </div>
                </div>

                <div class="fieldBox">
                    <div class="label">应收日期</div>
                    <div class="field">
                        <input ligerui="width: 83" name="ovdDtMin" id="ovdDtMin" type="text" class="ui-datepicker"
                               value="">
                        -
                        <input ligerui="width: 83" name="ovdDtMax" id="ovdDtMax" type="text" class="ui-datepicker"
                               value="">
                    </div>
                </div>

                <div class="fieldBox">
                    <div class="label">逾期金额</div>
                    <div class="field">
                        <input ligerui="width: 83" name="ovdAmtMin" id="ovdAmtMin" type="text" class="ui-textbox"
                               value="" validate="{number:true}">
                        -
                        <input ligerui="width: 83" name="ovdAmtMax" id="ovdAmtMax" type="text" class="ui-textbox"
                               value="" validate="{number:true}">
                    </div>
                </div>

                <div class="fieldBox">
                    <div class="label">分配状态</div>
                    <div class="field">
                        <input name="allocationFlag" id="allocationFlag" placeholder="请选择" ltype="combobox">
                    </div>
                </div>

                <div class="formBtns notRight">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                    <span id="assignTaskBtn" class="sq-button sq-button-round">分配</span>
                    <span id="backTaskBtn" class="sq-button sq-button-round">退回</span>
                </div>
                <div class="clearFix"></div>

            </div>
        </form>
    </div>

    <div id="ligergrid1" class="sq-grid"></div>

</div>

<script type="text/javascript">
    var grid = null, form = null;
    $(function () {
        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/risk/ovdCollect/initOvdList.do?queryType=2',
            method: 'get',
            columns: [
                {display: '客户名称', name: 'cstNm', minWidth: 150, align: 'left', enabledSort: false},
                {display: '逾期合同数', name: 'ovdCntQty', width: 100, align: 'right', enabledSort: false},
                {display: '逾期支付表数', name: 'ovdPayQty', width: 100, align: 'right', enabledSort: false},
                {display: '逾期天数', name: 'ovdDays', width: 100, align: 'right', enabledSort: false},
                {
                    display: '应收金额(元)', name: 'arAmt', width: 100, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.arAmt / 100);
                    }
                },
                {
                    display: '逾期金额(元)', name: 'ovdAmt', width: 100, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.ovdAmt / 100);
                    }
                },
                {
                    display: '罚息金额(元)', name: 'fineAmt', width: 100, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.fineAmt / 100);
                    }
                },
                {display: '任务人', name: 'usrNm', width: 80, align: 'center', enabledSort: false},
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            rownumbers: true,  //显示序号
            checkbox: true,
            allowUnSelectRow: true,
            alternatingRow: true,
        });
        grid.setHeight(100);

        //事业部
        $("#buOrgCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        //是否已分配
        $("#allocationFlag").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        form = $("#searchBar").ligerForm();
        liger.get("buOrgCd").setData(${buOrgCdList});
        liger.get("allocationFlag").setData([{"key":"0","value":"未分配"},{"key":"1","value":"已分配"}]);

        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            clearLigerForm("searchBar");
        });

        //分配催收任务
        $("#assignTaskBtn").click(function (event) {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length == 0) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
                return;
            }
            var _ids = [];
            var existIds =[];
            for (var index in selectedRows) {
                if(selectedRows[index].usrNm == null || selectedRows[index].usrNm == ''){
                    _ids.push(selectedRows[index].cstId);
                }else{
                    existIds.push(selectedRows[index].cstId);
                }
            }
            if(existIds.length > 0){
                $.ligerDialog.SQalert({content: "请选择没有任务人的数据进行分配操作.", SQ_type: "warning"});
                return ;
            }
            var onCancel = function (item, Dialog) {
                Dialog.hide();
            };
            $.ligerDialog.SQopen({
                width: 650,
                height: 500,
                title: '分配任务',
                url: '<%=path%>/risk/rskUsrCstR/toListPage.do',
                buttons: [
                    {
                        text: "关闭", onclick: onCancel, type: 'cancel'
                    }
                ],
                data: {ids: _ids},
            });

        });
    });

    //退回催收任务
    $("#backTaskBtn").click(function (event) {
        var selectedRows = grid.getSelectedRows();
        if (selectedRows.length == 0) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
            return;
        }
        var _ids = [];
        for (var index in selectedRows) {
            if(selectedRows[index].usrNm != null && selectedRows[index].usrNm != ''){
                _ids.push(selectedRows[index].cstId);
            }
        }
        if(_ids.length == 0){
            $.ligerDialog.SQalert({content: "请选择正确的数据进行退回操作.", SQ_type: "warning"});
            return ;
        }
        var data = JSON.stringify(_ids);
        var wait_dialog;
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {"ids":data},
            url: '<%=path%>/risk/rskUsrCstR/removeByIds.do',
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    grid.reload();
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });

    });
    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }
</script>

</body>
</html>
